package com.qingke.qixi.command;

import java.util.HashMap;
import java.util.Map;

import com.qingke.qixi.command_impl.EditCommand;
import com.qingke.qixi.command_impl.ExitCommand;
import com.qingke.qixi.command_impl.HelpCommand;
import com.qingke.qixi.command_impl.InviteCommand;
import com.qingke.qixi.command_impl.ListCommand;
import com.qingke.qixi.command_impl.LoginCommand;
import com.qingke.qixi.command_impl.LogoutCommand;
import com.qingke.qixi.command_impl.NewCommand;
import com.qingke.qixi.command_impl.SignupCommand;

public class CommandFactory {
	
	protected static Map<CommandCode, Class<? extends Command> > commandMap = new HashMap<CommandCode, Class<? extends Command>>();
	static{
		commandMap.put(CommandCode.EDIT, EditCommand.class);
		commandMap.put(CommandCode.HELP, HelpCommand.class);
		commandMap.put(CommandCode.INVITE, InviteCommand.class);
		commandMap.put(CommandCode.LIST, ListCommand.class);
		commandMap.put(CommandCode.LOGIN, LoginCommand.class);
		commandMap.put(CommandCode.LOGOUT, LogoutCommand.class);
		commandMap.put(CommandCode.EXIT, ExitCommand.class);
		commandMap.put(CommandCode.NEW, NewCommand.class);
		commandMap.put(CommandCode.SIGNUP, SignupCommand.class);
	}
	
	public Command buildCommand(CommandCode cmdCode){
		try {
			Class<? extends Command> cmdClass = commandMap.get(cmdCode);
			return cmdClass.newInstance();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
